abstract class FruitHandler {
    private FruitHandler next;

    public void setNext(FruitHandler next) {
        this.next = next;
    }

    public Fruit handleRequest(String kind) {
        Fruit fruit = createFruit(kind);
        if (fruit != null) {
            return fruit;
        } else if (next != null) {
            return next.handleRequest(kind);
        }
        return null;
    }

    protected abstract Fruit createFruit(String kind);
}